<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Excel处理器</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
            padding: 20px;
        }
        .container {
            max-width: 800px;
        }
        .card {
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            border: 1px solid rgba(0, 0, 0, 0.125);
        }
        .form-label {
            font-weight: 500;
        }
        .btn-submit {
            background-color: #007bff;
            border-color: #007bff;
        }
        .btn-submit:hover {
            background-color: #0056b3;
            border-color: #0056b3;
        }
        .processing {
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="text-center mb-4">Excel处理器</h1>
        
        <div class="card">
            <div class="card-body">
                <div class="mb-3 p-3 bg-light border rounded">
                    <p><strong>功能说明：</strong></p>
                    <ul class="mb-0">
                        <li>根据Excel文件中的比赛信息批量生成海报</li>
                        <li>为每张海报生成对应的视频</li>
                        <li>Excel文件需要包含：比赛时间、球队A、球队A队标链接、球队B、球队B队标链接、文案 等列</li>
                        <li>生成的海报和视频将保存到指定的输出目录</li>
                    </ul>
                </div>
                
                <!-- 显示闪现消息 -->
                <div class="mb-3">
                    {% with messages = get_flashed_messages(with_categories=true) %}
                        {% if messages %}
                            {% for category, message in messages %}
                                <div class="alert alert-{{ 'success' if category == 'message' else category }} alert-dismissible fade show" role="alert">
                                    {{ message }}
                                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                </div>
                            {% endfor %}
                        {% endif %}
                    {% endwith %}
                </div>
                
                <form id="excelForm">
                    <div class="mb-3">
                        <label for="excel_path" class="form-label">Excel文件路径:</label>
                        <input type="text" class="form-control" id="excel_path" name="excel_path" 
                               value="{{ cached_inputs.get('excel_path', '') }}" placeholder="例如：C:\data\matches.xlsx" required>
                        <div class="form-text">包含比赛信息的Excel文件路径</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="audios_dir" class="form-label">音频目录:</label>
                        <input type="text" class="form-control" id="audios_dir" name="audios_dir" 
                               value="{{ cached_inputs.get('audios_dir', '') }}" placeholder="例如：C:\data\audios" required>
                        <div class="form-text">包含背景音乐的目录路径</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="output_dir" class="form-label">输出目录:</label>
                        <input type="text" class="form-control" id="output_dir" name="output_dir" 
                               value="{{ cached_inputs.get('output_dir', '') }}" required>
                        <div class="form-text">处理结果的输出目录</div>
                    </div>
                    
                    
                    <button type="submit" class="btn btn-submit btn-primary w-100">开始处理</button>
                    
                    <div class="processing mt-3">
                        <div class="spinner-border text-primary" role="status">
                            <span class="visually-hidden">处理中...</span>
                        </div>
                        <span class="ms-2">正在提交任务...</span>
                    </div>
                </form>
            </div>
        </div>
        
        <div class="text-center mt-4">
            <a href="{{ url_for('index') }}" class="btn btn-outline-primary">← 返回主页</a>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('excelForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 显示处理状态
            document.querySelector('.processing').style.display = 'block';
            
            // 获取表单数据
            const formData = new FormData(this);
            
            // 发送请求
            fetch('/excel-process', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 跳转到任务状态页面
                    window.location.href = '/excel-task/' + data.task_id;
                } else {
                    alert('提交失败: ' + data.error);
                    document.querySelector('.processing').style.display = 'none';
                }
            })
            .catch(error => {
                alert('提交出错: ' + error);
                document.querySelector('.processing').style.display = 'none';
            });
        });
    </script>
</body>
</html>